#!/bin/bash

# 设置变量
PROJECT_ROOT=$(pwd)
DIST_DIR="$PROJECT_ROOT/dist"
BUILD_DIR="$PROJECT_ROOT/build"
INCLUDE_DIR="$PROJECT_ROOT/include"

# 清理旧的发布目录
rm -rf "$DIST_DIR"

# 创建发布目录结构
mkdir -p "$DIST_DIR/include"
mkdir -p "$DIST_DIR/lib"

# 清理并创建构建目录
rm -rf "$BUILD_DIR"
mkdir -p "$BUILD_DIR"
cd "$BUILD_DIR"

# Release 模式构建
cmake .. -DCMAKE_BUILD_TYPE=Release
make -j$(nproc)

# 复制头文件
cp -r "$INCLUDE_DIR/MarketEngine.h" "$DIST_DIR/include/"
cp -r "$INCLUDE_DIR/CTP" "$DIST_DIR/include/"

# 复制库文件
cp "libMarketEngine.so" "$DIST_DIR/lib/"

# 创建使用说明
cat > "$DIST_DIR/README.md" << 'EOF'
# MarketEngine Library

## 目录结构
```
dist/
├── include/          # 头文件
│   ├── CTP/         # CTP API 头文件
│   └── MarketEngine.h
└── lib/             # 库文件
    └── libMarketEngine.so
```

## 使用方法

1. 包含头文件
```cpp
#include "MarketEngine.h"
```

2. 链接库文件
在 CMakeLists.txt 中：
```cmake
target_link_libraries(your_target PRIVATE
    MarketEngine
)
```

3. 运行时依赖
- Qt 5.x
- CTP API 动态库
EOF

# 打包
cd "$PROJECT_ROOT"
tar -czf MarketEngine.tar.gz dist/

echo "Package created successfully: MarketEngine.tar.gz"
echo "Contents:"
tar -tvf MarketEngine.tar.gz 